package com.ycsj.goldmedalnewconcept.parent.activity;


import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.ycsj.common.base.BaseActivity;
import com.ycsj.common.base.BaseApplication;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.HttpAddress;
import com.ycsj.goldmedalnewconcept.common.http.HttpCallBack;
import com.ycsj.goldmedalnewconcept.common.http.HttpUtils;
import com.ycsj.goldmedalnewconcept.master.bean.MsgInfo;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 家长端查看教学目标
 * Created by Administrator on 2019/5/7 0007.
 */

public class ParentLookTeacherTargetActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_fs)
    TextView tvFs;
    @BindView(R.id.ll_content)
    LinearLayout llContent;
    @BindView(R.id.rl_loading)
    RelativeLayout rlLoading;

    //单元号
    private String unit;

    /**
     * 跳转当前界面的方法
     *
     * @param context
     * @param unit
     */
    public static void goActivity(Context context, String unit) {
        Intent it = new Intent(context, ParentLookTeacherTargetActivity.class);
        it.putExtra("unit", unit);
        context.startActivity(it);
    }

    @Override
    protected int getContentLayout() {
        return R.layout.parent_activity_look_target;
    }

    @Override
    protected void init() {

        initStateBar();

        //获取跳转数据
        initIntent();

        //初始化标题
        initTitle();

        //请求教学目标的数据
        http();
    }


    /**
     * 获取传递的数据
     */
    private void initIntent() {
        unit = getIntent().getStringExtra("unit");
    }

    /**
     * 初始化标题栏
     */
    private void initTitle() {
        tvTitle.setText("教学目标");
    }

    /**
     * 请求教学目标的数据
     */
    private void http() {
        Map<String, String> map = new HashMap<>();
        map.put("type", "17");
        map.put("unit", unit);

        HttpUtils.post(HttpAddress.ZNDMSG, map, this, new HttpCallBack<MsgInfo>() {
            @Override
            public void onSuccess(MsgInfo msgInfo) {
                rlLoading.setVisibility(View.GONE);
                llContent.setVisibility(View.VISIBLE);

                //设置页面数据,默认显示教学目标
                if (!TextUtils.isEmpty(msgInfo.content)) {
                    tvFs.setText(Html.fromHtml(msgInfo.content));
                } else {
                    tvFs.setText("暂无数据");
                }
            }

            @Override
            public void onError(String e) {
                rlLoading.setVisibility(View.GONE);
                ToastUtils.showShort(BaseApplication.ERROR);
            }
        });
    }


    /**
     * 点击事件
     *
     * @param v
     */
    @OnClick({R.id.iv_back})
    public void onViewClicked(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                //返回
                finish();
                break;
        }
    }
}
